<%-- 自定义实体添加页面 --%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>

<!DOCTYPE>
<html>
<head>
    <!-- 引入通用js、css文件(xiaogq) -->
    <meta name="decorator" content="bootstrap"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/system/custom/entity/entity_add.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>
</head>
<body>
<!-- 加载列表操作 -->
<div class="button_list">
    <a href="javascript:;" onclick="saveEntity()">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_SAVE.png"></span>
                <span name="buTitle">保存</span>
            </span>
    </a>
    <a href="javascript:;" onclick="javascript:parent.closeTab();">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_CANCEL.png"></span>
                <span name="buTitle">取消</span>
            </span>
    </a>
</div>

<div class="content row">
    <h3>基础信息</h3>
    <hr>
    <form role="form" class="entityForm" id="entity_form" method="post">
        <input type="hidden" id="id" name="id" value="${operation.id}">
        <div class="form-group col-lg-5 col-md-10 pull-left" >
            <label class="pull-left">操作名称: <span style="color: red">*</span></label>
            <input type="text" class="form-control" id="name" name="name" value="${operation.name}">
        </div>
        <div class="form-group col-lg-5 col-md-10" style="margin-left:-10px" >
            <label class="pull-left">显示位置: </label>
            <div>
                <label class="checkbox-inline">
                    <input type="checkbox" id="showList" <c:if test="${operation.showList}">checked</c:if> >列表
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" id="showColumn" <c:if test="${operation.showColumn}">checked</c:if> >列前
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" id="showView" <c:if test="${operation.showView}">checked</c:if> >详情页
                </label>
            </div>
        </div>
        <div class="form-group col-lg-5 col-md-10 pull-left" >
            <label class="pull-left">描述: </label>
            <input type="text" class="form-control" id="description" name="description" value="${operation.description}">
        </div>
    </form>
</div>

<script type="text/javascript">
    function validateMethod(){
        var flag = true;
        var name = $("#name").val();
        if(name == ""){
            alert("操作名称不能为空!");
            flag = false;
            $("#name").focus();
            return flag;
        }
        return flag;
    }

    //自定义实体保存方法(xiaogq)
    function saveEntity(){
        var flag = validateMethod();
        if(flag){
            var id = $("#id").val();
            var name = $("#name").val();
            var showColumn = $("#showColumn").is(':checked');
            var showList = $("#showList").is(':checked');
            var showView = $("#showView").is(':checked');
            var description = $("#description").val();
            $.ajax({
                type: 'POST',
                url: getRootPath()+"/"+Constants.editOperationUrl,
                data : {id:id,name:name,showList:showList,showColumn:showColumn,showView:showView,description:description},
                dataType: 'json',
                success: function(data) {
                    var results = data.results;
                    if(results == "success"){
                        parent.closeTab(1);
                    }else{
                        alert("添加操作未成功!");
                    }
                },
                error: function(data) {
                    alert("添加操作发生错误!");
                }
            });
        }
    }
</script>
</body>
</html>
